<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-3
 * Time: PM4:03
 */

include_once '../common.func.php';

$links = getLinks();

$id = intval($_POST['id']);
$content = trim($_POST['content']);
$href = trim($_POST['href']);
$title = trim($_POST['title']);

if ($_POST['action'] == '保存') {
    if ($links[$id]) {
        $links[$id]['content'] = $content;
        $links[$id]['href'] = $href;
        $links[$id]['title'] = $title;
        saveLinks($links);
    }
} elseif ($_POST['action'] == '删除') {
    unset($links[$id]);
    saveLinks(array_values($links));
} elseif ($_POST['action'] == '添加') {
    array_push($links, array('content' => $content, 'href' => $href, 'title' => $title));
    saveLinks($links);
}


header('Location: ../admin/link.php');
